<%@ page contentType="text/html;charset=UTF-8" language="java"  import="java.util.*" trimDirectiveWhitespaces="true" %>
<%@include file="/WEB-INF/pages/common/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>主石参数设置新增</title>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <%@include file="/WEB-INF/pages/common/commonCss.jsp"%>
    <link rel="stylesheet" href="${basePath}/resources/css/colorpicker.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/datepicker.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/uniform.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/select2.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/matrix-style.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/matrix-media.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/bootstrap-wysihtml5.css" />


</head>
<style>
    .select2-container {
        float:left;
        width: 35%;
    }
    em,strong{ color:#C00;}
    span.error{color:#C00; padding:0 6px;}

</style>
<body>

<!--Header-part-->
<%@include file="/WEB-INF/pages/common/head.jsp"%>


<!--sidebar-menu-->
<%@include file="/WEB-INF/pages/common/left.jsp"%>

<div id="content">
    <div id="content-header">
        <div id="breadcrumb"> <a href="#" title="Go to Home" class="tip-bottom"><i class="icon-home"></i> </a>
            <a href="#" class="current">主石参数设置新增</a> </div>
        <%--<h1>平台商品新增</h1>--%>
    </div>

    <div class="container-fluid">


        <div class="row-fluid">
            <div class="span12">
                <div class="widget-box">
                    <div class="widget-title"> <span class="icon"> <i class="icon-align-justify"></i> </span>
                        <h5></h5>
                    </div>
                    <div class="widget-content nopadding">
                        <form  id="form" method="POST" class="form-horizontal" >



                            <div class="control-group" >
                                <label class="control-label">重量级别:</label>
                                <div class="controls">
                                    <select  name="dcId"  id="dcId"   >
                                        <c:forEach items="${allLevel}" var="level">
                                            <option value="${level.id}">${level.start}≤重量<${level.end} &nbsp; ${level.price}元</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>

                            <div class="control-group" >
                                <label class="control-label">参数类型:</label>
                                <div class="controls">
                                    <select  name="type"  id="type"  onchange="diamondParmCalculation.change()" >
                                        <c:forEach items="${allType}" var="type">
                                            <option value="${type.codevalue}">${type.dictname}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>


                            <div class="control-group">
                                <label class="control-label">规格:</label>
                                <div class="controls">
                                    <select  name="spec"  id="spec"   >

                                    </select>
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label">价格比:</label>
                                <div class="controls">
                                    <div class="input-append">
                                        <input type="number" name="rate" id="rate"  placeholder="0" class="span11"   required >
                                     </div>
                                </div>
                            </div>


                            <div class="control-group">
                                <div class="controls">
                                    <button  type="submit"  onclick="" class="btn btn-success">保存</button>
                                    <button type="reset" class="btn btn-default" onclick="history.go(-1)">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>


<!-- Modal -->

</div>



<!--Footer-part-->
<%@include file="/WEB-INF/pages/common/footer.jsp"%>

<!--end-Footer-part-->

<%@include file="/WEB-INF/pages/common/commonJS.jsp"%>
<%--<script src="${basePath}/resources/js/bootstrap.min.js"></script>--%>
<script src="${basePath}/resources/js/jquery.validate.js"></script>
<script src="${basePath}/resources/js/admin/validate.js"></script>
<script src="${basePath}/resources/js/admin/myvalidata.js"></script>



<script>
    $(function(){
        //jquery.validate
        $("#form").validate({
            submitHandler: function() {
                //验证通过后 的js代码写在这里
                var $form = $(form);
                var rate = $('#rate').val();
                if(!hfl_validate.testNumberDot3(rate)){
                    $('#rate').val("").focus();
                    loading("请输入0-1的3位小数",5);
                    return;
                }
                var data = $form.serialize();
                console.log(JSON.stringify(data));
                diamondParmCalculation.save(data);

            }
        })

    })

    var diamondParmCalculation = {
        //切换
        change:function() {
            var codevalue = $('#type').val();
            $.ajax({
                url:adminPath +'/service/diamondparmcalculation/getAllspec',
                type:'POST',
                data:{codevalue:codevalue},
                success:function (data) {
                    var html= "";
                    if(data && data.length>0){
                        for(var i=0,len=data.length;i<len;i++){
                            html +=  " <option value='"+data[i].codevalue+"'>"+data[i].dictname+"</option>";
                        }
                        $("#spec").html(html);
                    }
                }
            });
            console.log(22);
        },
        //保存
        save:function (data) {
            $.ajax({
                url:adminPath +'/service/diamondparmcalculation/save',
                type:'POST',
                data:data,
                success:function (data) {
                    if(data == 1){
                        window.location.href =  adminPath +"/service/diamondparmcalculation/list";
                    }
                    if(data==0){
                        loading("该记录重复，请重新添加",5);
                    }
                }
            });
        }
        
    };



</script>
<script>
    $(function () {
        diamondParmCalculation.change();
    })
</script>

</body>
</html>
